package cc.catface.mess.mybatisp.mapper;

import cc.catface.mess.mybatisp.pojo.User;
import cc.catface.mess.mybatisp.pojo.UserAndCourseOutDTO;
import cc.catface.mess.mybatisp.pojo.UserConvert;
import cc.catface.mess.mybatisp.pojo.UserUpper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /*=============mybatis-plus=============*/
    @Select("select name,age,email mail from user where age>#{age}")
    List<User> selectByAge(int age);

    @Select("select user.*,user.id as uid,user.name as uname,course.*,course.id as cid, course.name as cname from user left join course on user.id=course.user_id")
    List<UserAndCourseOutDTO> selectUserAndCourse();

    @Select("select user.*,user.id as uid,user.name as uname,course.*,course.id as cid, course.name as cname from user right join course on user.id=course.user_id")
    Page<UserAndCourseOutDTO> selectUserAndCoursePage(Page page);


    /*=============xml=============*/
    List<User> allUser(boolean asc);

    void add(@Param("u") User user);//使用@Param

    List<UserConvert> allUserConvert();

    List<UserUpper> allUserUpper();

    List<User> foreachList(@Param("names") List<String> names);

    List<User> foreachArray(@Param("names") String[] names);

    void foreachMap(@Param("map") Map<String, Object> map);
}
